package com.ququ.syb.business.account.controller;

import com.ququ.common.result.Result;
import com.ququ.common.result.ResultJson;
import com.ququ.syb.business.account.service.AccountBusinessService;
import com.ququ.syb.common.pojo.AccountInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AccountBusinessController {
    @Autowired
    private AccountBusinessService accountBusinessService;


    //注册生意宝账户
    @RequestMapping("/register")
    public Result<AccountInfo> register(@RequestParam(required = false) String accountid,
                                        @RequestParam(required = false) String name,
                                        @RequestParam String mobile,
                                        @RequestParam(required = false) String accountname,
                                        @RequestParam String appcode,
                                        @RequestParam(required = false) String partner,
                                        @RequestParam(required = false) String idcardno,
                                        @RequestParam(required = false) String password){
        return accountBusinessService.register(accountid, name, mobile, accountname, appcode, partner, idcardno, password);
    }

    //查询生意宝账户
    @RequestMapping("/query")
    public Result<AccountInfo> getAccountInfo(@RequestParam String accountid){
        return accountBusinessService.getAccountInfo(accountid);
    }

    //获取token
    @RequestMapping("/token")
    public Result<String> getToken(@RequestParam String accountid){
        return accountBusinessService.getToken(accountid);
    }

    //获取交易密码
    @RequestMapping("/password")
    public Result<String> getPassword(@RequestParam String accountid){
        return accountBusinessService.getPassword(accountid);
    }

    //检查交易密码
    @RequestMapping("/password/check")
    public Result<Integer> checkPassword(@RequestParam String accountid,
                                         @RequestParam String password){
        return accountBusinessService.checkPassword(accountid, password);
    }

    //修改生意宝账户
    @RequestMapping("/update")
    public Result<AccountInfo> update(
            @RequestParam String accountid,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String mobile,
            @RequestParam(required = false) String accountname,
            @RequestParam(required = false) String appcode,
            @RequestParam(required = false) String partner,
            @RequestParam(required = false) String idcardno,
            @RequestParam(required = false) Integer allowpay,
            @RequestParam(required = false) Integer allowwithdraw,
            @RequestParam(required = false) String token,
            @RequestParam(required = false) String password,
            @RequestParam(required = false) Integer status){
        return accountBusinessService.update(accountid, name, mobile, accountname, appcode, partner, idcardno, allowpay, allowwithdraw, token, password, status);
    }

    //重置交易密码
    @RequestMapping("/password/set")
    public ResultJson setPassword(@RequestParam String accountid,
                                  @RequestParam String password){
        return accountBusinessService.setPassword(accountid, password);
    }

    //冻结生意宝账户
    @RequestMapping("/freeze")
    public ResultJson freezeAccount(@RequestParam String accountid) {
        return accountBusinessService.freezeAccount(accountid);
    }
    //解冻生意宝账户
    @RequestMapping("/unfreeze")
    public ResultJson unfreezeAccount(@RequestParam String accountid) {
        return accountBusinessService.unfreezeAccount(accountid);
    }

    //检查是否冻结
    @RequestMapping("/freeze/check")
    public Result<Integer> checkAccountFreezeStatus(@RequestParam String accountid) {
        return accountBusinessService.checkAccountFreezeStatus(accountid);
    }
    //列出所有冻结账户
    @RequestMapping("/freeze/list")
    public Result<List<AccountInfo>> listFreezeAccountInfo(){
        return accountBusinessService.listFreezeAccountInfo();
    }

    //修改允许支付状态
    @RequestMapping("/allow/pay/set")
    public Result<AccountInfo> setAllowPay(@RequestParam String accountid,
                                           @RequestParam Integer allowpay){
        return accountBusinessService.setAllowPay(accountid, allowpay);
    }

    //检查是否允许支付
    @RequestMapping("/allow/pay")
    public Result<Integer> getAllowPay(@RequestParam String accountid) {
        return accountBusinessService.getAllowPay(accountid);
    }

    //修改允许提现状态
    @RequestMapping("/allow/withdraw/set")
    public Result<AccountInfo> setAllowWithdraw(@RequestParam String accountid,
                                                @RequestParam Integer allowwithdraw){
        return accountBusinessService.setAllowWithdraw(accountid, allowwithdraw);
    }

    //检查是否允许提现
    @RequestMapping("/allow/withdraw")
    public Result<Integer> getAllowWithdraw(@RequestParam String accountid) {
        return accountBusinessService.getAllowWithdraw(accountid);
    }
}
